<template>
  <div class="base-input">
    <input ref="ipt" :type="type" :placeholder="placeholder" :value="value" @input="$emit('input', $event.target.value)" />
  </div>
</template>

<script>
export default {
  name: 'BaseInput',
  props: {
    value: String,
    autofocus: {
      type: Boolean,
      default: false,
    },
    type: {
      type: String,
      default: 'text',
      validator(v) {
        return ['text', 'password'].includes(v)
      },
    },
    placeholder: String,
  },
  mounted() {
    this.autofocus && this.$refs.ipt.focus()
  },
  methods: {
    focus() {
      this.$refs.ipt.focus()
    },
  },
}
</script>

<style scoped>
.base-input {
  position: relative;
  font-size: 14px;
  display: inline-block;
}
.base-input input {
  font-size: 15px;
  appearance: none;
  margin-bottom: 5px;
  box-sizing: border-box;
  color: #6a4d52;
  border-radius: 5px;
  border: 1px solid #dcdfe6;
  padding: 0 15px;
  height: 40px;
  line-height: 40px;
  outline: none;
}
.base-input input:focus {
  outline: none;
  border-color: #409eff;
}
.base-input + .base-input {
  margin-left: 5px;
}
</style>
